﻿using Prism.Services.Dialogs;
using System;
using System.Timers;

namespace Base.ModuleBase.Dialogs.ViewModels
{
    public class TipDialogViewModel : DialogViewModelBase
    {
        /// <summary>
        /// 自动关闭
        /// </summary>
        Timer autoCloseTimer = null;

        private string _message;
        /// <summary>
        /// 提示内容
        /// </summary>
        public string Message
        {
            get { return _message; }
            set { SetProperty(ref _message, value); }
        }

        public TipDialogViewModel()
        {
            Title = "提示";

            autoCloseTimer = new Timer();
            autoCloseTimer.AutoReset = false;
            autoCloseTimer.Interval = 2000;
            autoCloseTimer.Elapsed += AutoCloseTimer_Elapsed;
            autoCloseTimer.Start();
        }

        private void AutoCloseTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            UiDispatcherHelper.Invoke(() =>
            {
                CloseDialogCommand.Execute("");
            });
        }

        public override void OnDialogOpened(IDialogParameters parameters)
        {
            Message = parameters.GetValue<string>("message");
        }
    }
}
